package com.javaweb.text;

import com.alibaba.fastjson.JSON;
import com.util.JDBCUtil;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
@WebServlet("/user")
public class LaYuiTest extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=utf-8");
        Integer page = Integer.valueOf(req.getParameter("page"));
        Integer size = Integer.valueOf(req.getParameter("size"));
        List<User> list = JDBCUtil.getList(User.class, "select * from test_table limit ?,?", (page - 1) * size, size);
        Integer count = JDBCUtil.getCount("select count(1) from test_table");
        Response res = new Response(count, list);
        resp.getWriter().write(JSON.toJSONString(res));

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
